package com.anuprayog.flyinghelicopter;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import android.R.integer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
import android.content.ContextWrapper;
import java.io.File;

/**
 * @author amit
 * This activity displays the highest score achieved by the user
 */
public class HighActivity extends Activity {

        private TextView textview;
       
        public int HIGH_SCORE;
       
         private String filename = "MyFile.txt";
         private String filepath = "MyFileStorage";
         File myInternalFile;

       
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_high);
               
                //code added by manoj chand on 23 july 2013
                ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext());
                File directory = contextWrapper.getDir(filepath, Context.MODE_PRIVATE);
                myInternalFile = new File(directory , filename);
                HIGH_SCORE = getHighScore();
                textview = (TextView) findViewById(R.id.textView5);
               
                textview.setText("Best Score:" + HIGH_SCORE);
               
                textview.setTextColor(Color.YELLOW);
        }
       
        //function created by manoj chand to get high score from internal storage.
        public int getHighScore(){
                String myData="0";
                   try {
                            FileInputStream fis = new FileInputStream(myInternalFile);
                            DataInputStream in = new DataInputStream(fis);
                            BufferedReader br = new BufferedReader(new InputStreamReader(in));
                            String strLine;
                            while ((strLine = br.readLine()) != null) {
                             myData = strLine;
                            }
                            in.close();
                           } catch (IOException e) {
                            e.printStackTrace();
                           }
                   if(myData != null && myData.trim().equals(""))
                           myData="0";
                   return Integer.parseInt(myData);
                }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                // Inflate the menu; this adds items to the action bar if it is present.
                getMenuInflater().inflate(R.menu.high, menu);
                return true;
        }
       
        public void goBack(View view) {
                finish();
    }

}
